﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Albon.Model;

namespace AlbonWeb.Manager.MessageManager
{
    public partial class MessageReply : System.Web.UI.Page
    {
        private readonly BLL.MessageBLL messagebll = new BLL.MessageBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["Back"] = Request.UrlReferrer.ToString();
                if (Request["id"] != null)
                {
                    messageShow.Text = messagebll.getMessage(Request["id"].ToString());
                }
            }
        }

        protected void addMessage_Click(object sender, EventArgs e)
        {
            Message message = new Message();
            //发信人是当前登录用户，收信人是当前对话的另外一个人
            message.sender = User.Identity.Name;
            int refID=int.Parse(messagebll.getMessageByID(Request["id"].ToString()).Rows[0]["refID"].ToString());
            message.refID = refID == 0 ? int.Parse(Request["id"].ToString()) : refID; 
            message.content = tbContent.Text;
            messagebll.replyMessage(message);
            messageShow.Text = messagebll.getMessage(Request["id"].ToString());
        }

        //返回
        protected void goBack_Click(object sender, EventArgs e)
        {
            Response.Redirect(ViewState["Back"].ToString());
        }
    }
}